$(function(){
	var u = $.cookie("youleche.u");
	if(u == null){
		window.parent.location.href="../noresponse.jsp";
		return;
	}
	$.ajax({
		type: "get",
		dataType: "text",
		url: "../au.do?action=3&userName="+u,
		success: function(v){
			eval("var user = " + v);
			
			$("#txtQQ").val(user.a5);
			$("#txtemail").val(user.email);
			$("#txtuserName").val(user.userName).css("text-align", "center");
			$("#txtPhone").val(user.phoneNum).css("text-align", "center");
			$("#hidUserId").val(user.id);
			if(user.shopImgUrl != "0"){
				var imgSrc = "/meileche/userImage/" + user.shopImgUrl;
				var html = "<img id=\"cerImg\" src=\""+imgSrc+"\"/>";
	            $("#cerDiv").html(html);
			}
			
			
			$("#fileupload").attr("data-url", ctx + "/img.do?action=3&id=" + user.id);
			$('#fileupload').fileupload({
				dataType: 'text',
		        done: function (e, data) {
		        	var result = data.result;
		        	var html = "<img id=\"cerImg\" src=\""+result+"\"/>";
		            $("#cerDiv").html(html);
		        }
			});
			var a4 = user.a4;
			if(a4 == "1"){
				$("#trSjWarn").hide();
				$.ajax({
					type: "get",
					dataType: "text",
					url: "../sell.do?action=0&userName="+u,
					success: function(v){
						eval("var seller = " + v);
						$("#txtShopName").val(seller.shopName);
						$("#txtShopAddress").val(seller.shopAddress);
						
						
					}
				});
			}else{
				$("#trSjShop").hide();
				$("#trSjShopWarn").hide();
				$("#trSjShopAddress").hide();
				$("#trSjShopAddressWarn").hide();
				$("#trSjShopRz").hide();
				$("#trSjShopRz1").hide();
			}
		}
	});
	
	
	
	
});

function confirmModify(){
	var shopName = $("#txtShopName").val();
	var shopAddress = $("#txtShopAddress").val();
	var id = $("#hidUserId").val();
	var user = new Object();
	user.shopName = shopName;
	user.shopAddress = shopAddress;
	user.userId = id;
	user.shopImgUrl = "0";
	var json = JSON.stringify(user);
	var u = $("#txtuserName").val();
	$.ajax({
		type: "post",
		data: json,
		contentType: "application/json",
		dataType: "text",
		url: "../sell.do?action=1&userName="+u,
		success: function(v){
			var userName = $("#txtuserName").val();
			var phoneNum = $("#txtPhone").val();
			var userInfo = new Object();
			var A5 = $("#txtQQ").val();
			userInfo.userName = userName;
			userInfo.phoneNum = phoneNum;
			userInfo.id = id;
			userInfo.A5 = A5;
			var jsonUser = JSON.stringify(userInfo);
			$.ajax({
				type: "post",
				data: jsonUser,
				contentType: "application/json",
				dataType: "text",
				url: "../au.do?action=12",
				success: function(v){
					layer.alert("修改成功~~~", 9);
				}
			});
			
		},
		error: function(v){
			layer.alert("修改失败了~~~", 8);
		}
	});	
}

function deleteImg(){
	var src = $("#cerImg").attr("src");
	var userId = $("#hidUserId").val();
	$.ajax({
		type: "post",
		dataType: "text",
		url: ctx + "/img.do?action=4&id="+src +"&userId="+userId,
		success: function(v){
			$("#cerDiv").empty();
			layer.alert("删除成功~~~", 9);
		}
	});
}